package com.ge.med.cchelper.popup.actions;


import org.eclipse.core.resources.IProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

import com.ge.med.cchelper.form.LoginForm;
import com.ge.med.cchelper.util.ReourceHelper;

public class LoginAction implements IObjectActionDelegate{
	private Shell shell;
	public LoginAction(){
		super();
	}
	
	public void run(IAction arg0) {
		try {
			LoginForm inst = new LoginForm(shell, SWT.NULL);
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void selectionChanged(IAction arg0, ISelection arg1) {
		if (arg1 != null && arg1 instanceof IStructuredSelection) {
			IStructuredSelection obj = (IStructuredSelection) arg1;
			Object objs = obj.getFirstElement();
					
			if (objs instanceof IProject) {
				IProject currentProject = (IProject) objs;
				ReourceHelper.setProject(currentProject);
			}else{
				arg0.setEnabled(false);
			}
		}
		
	}

	
	public void setActivePart(IAction arg0, IWorkbenchPart arg1) {
		shell = arg1.getSite().getShell();
	}

}
